package servlet;

import dao.UserDao;
import org.omg.CORBA.Request;
import pojo.User;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author konley
 * @date 2020-06-17 16:43
 */
@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String msg = null;
        User user = new User(
                request.getParameter("name"),
                request.getParameter("password"),
                request.getParameter("tel"),
                request.getParameter("address")
        );
        System.out.println("user = " + user);
        new UserDao().addUser(user);
        msg = "注册成功！您现在可以登录了";
        request.setAttribute("msg",msg);
        request.getRequestDispatcher("/index.jsp").forward(request,response);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
